﻿using System;

namespace Slippor.Douban.Radio.Assist
{
    public interface ICommand
    {
        int X { get; }
        int Y { get; }
        Command Command { get; set; }
        String ID { get; set; }
    }

    public static class CommandFactory
    {
        public static ICommand GetCommand(Command command, RadioType radioType)
        {
            switch (command)
            {
                case Command.Control:
                    return new ControlCommand(radioType);
                case Command.Del:
                    if (radioType == RadioType.PrivateRadio)
                    {
                        return new DelCommand(radioType);
                    }
                    return new OtherCommand(radioType);
                case Command.Fav:
                    return new FavCommand(radioType);
                case Command.UnFav:
                    return new UnFavCommand(radioType);
                case Command.Next:
                    return new NextCommand(radioType);
                case Command.Filter:
                    return new FilterCommand(radioType);
                case Command.Search:
                    return new OtherCommand(radioType) { Command = Command.Search, ID ="Search" };
                case Command.Notify:
                    return new OtherCommand(radioType) { Command = Command.Notify, ID = "Display" };
                case Command.ShowInfo:
                    return new OtherCommand(radioType) { Command = Command.ShowInfo, ID = "ShowInfo" };
                default:
                    return new OtherCommand(radioType) {Command = command};
            }
        }
    }

    public class ControlCommand : ICommand
    {
        private RadioType _radioType = RadioType.PrivateRadio;

        public ControlCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get { return 300; }
        }

        public int Y
        {
            get { return 70; }
        }

        public Command Command
        {
            get { return Command.Control; }
            set { }
        }

        public String ID
        {
            get { return "Play"; }
            set { }
        }

        #endregion
    }

    public class FavCommand : ICommand
    {
        private readonly RadioType _radioType = RadioType.PrivateRadio;

        public FavCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get
            {
                switch (_radioType)
                {
                    //case RadioType.PublicRadio:
                    //    return 332;
                    default:
                        return 267;
                }
            }
        }

        public int Y
        {
            get { return 145; }
        }

        public Command Command
        {
            get { return Command.Fav; }
            set { }
        }

        public String ID
        {
            get { return "Like"; }
            set { }
        }

        #endregion
    }


    public class UnFavCommand : ICommand
    {
        private readonly RadioType _radioType = RadioType.PrivateRadio;

        public UnFavCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get
            {
                switch (_radioType)
                {
                    //case RadioType.PublicRadio:
                    //    return 332;
                    default:
                        return 267;
                }
            }
        }

        public int Y
        {
            get { return 145; }
        }

        public Command Command
        {
            get { return Command.UnFav; }
            set { }
        }

        public String ID
        {
            get { return "UnLike"; }
            set { }
        }

        #endregion
    }


    public class DelCommand : ICommand
    {
        private RadioType _radioType = RadioType.PrivateRadio;

        public DelCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get { return 320; }
        }

        public int Y
        {
            get { return 145; }
        }

        public Command Command
        {
            get { return Command.Del; }
            set { }
        }

        public String ID
        {
            get { return "Del"; }
            set { }
        }

        #endregion
    }

    public class NextCommand : ICommand
    {
        private RadioType _radioType = RadioType.PrivateRadio;

        public NextCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get { return 372; }
        }

        public int Y
        {
            get { return 145; }
        }

        public Command Command
        {
            get { return Command.Next; }
            set { }
        }

        public String ID
        {
            get { return "Next"; }
            set { }
        }

        #endregion
    }

    public class OtherCommand : ICommand
    {
        private Command _command = Command.Other;
        private String _name = String.Empty;
        private RadioType _radioType = RadioType.PrivateRadio;

        public OtherCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get { return 0; }
        }

        public int Y
        {
            get { return 0; }
        }

        public Command Command
        {
            get { return _command; }
            set { _command = value; }
        }

        public String ID
        {
            get { return _name; }
            set { _name = value; }
        }

        #endregion
    }

    public class FilterCommand : ICommand
    {
        private RadioType _radioType = RadioType.PrivateRadio;

        public FilterCommand(RadioType radioType)
        {
            _radioType = radioType;
        }

        #region ICommand Members

        public int X
        {
            get { return 372; }
        }

        public int Y
        {
            get { return 145; }
        }

        public Command Command
        {
            get { return Command.Filter; }
            set { }
        }

        public String ID
        {
            get { return "Filter"; }
            set { }
        }

        #endregion
    }

    public  class FakeClickCommand :ICommand
    {
        private int _x = 0;
        private int _y = 0;

        public FakeClickCommand(int x,int y)
        {
            _x = x;
            _y = y;
        }

        #region ICommand Members

        public int X
        {
            get { return _x; }
        }

        public int Y
        {
            get { return _y; }
        }

        public Command Command
        {
            get { return Command.FakeClick; }
            set { }
        }

        public String ID
        {
            get { return "Fake"; }
            set { }
        }

        #endregion
    }
}